#include "mcsettingstest.h"
#include "mcsettings.h"

#include <cppunit/config/SourcePrefix.h>

using namespace MCCommon;

CPPUNIT_TEST_SUITE_REGISTRATION( TestMCSettings );

TestMCSettings::TestMCSettings()
{
}

TestMCSettings::~TestMCSettings()
{
}

void
TestMCSettings::Test()
{
    MCSettings settings;
    bool isOK;

    // Test add settings.
    {
        isOK = settings.AddSetting( "a", 1 );
        CPPUNIT_ASSERT( isOK );
        isOK = settings.AddSetting( "b", 2.0 );
        CPPUNIT_ASSERT( isOK );
        isOK = settings.AddSetting( "c", true );
        CPPUNIT_ASSERT( isOK );
        isOK = settings.AddSetting( "d", "han" );
        CPPUNIT_ASSERT( isOK );

        std::vector< int > vi;
        vi.push_back( 1 );
        vi.push_back( 2 );
        isOK = settings.AddSetting("e", vi );
        CPPUNIT_ASSERT( isOK );

        isOK = settings.AddSetting( "f", settings ); 
        CPPUNIT_ASSERT( isOK );   

        isOK = settings.AddSetting( "f", 2 ); 
        CPPUNIT_ASSERT( !isOK );  
    }

    {
        int i;
        bool b;
        std::string s;
        double d;

        isOK = settings.GetSetting( "a", i );
        CPPUNIT_ASSERT( isOK );
        CPPUNIT_ASSERT( i == 1 );
        isOK = settings.GetSetting( "b", d );
        CPPUNIT_ASSERT( isOK );
        CPPUNIT_ASSERT( d == 2.0 );
        isOK = settings.GetSetting( "c", b );
        CPPUNIT_ASSERT( isOK );
        CPPUNIT_ASSERT( b == true );
        
        isOK = settings.GetSetting( "d", s );
        CPPUNIT_ASSERT( isOK );
        CPPUNIT_ASSERT( s == "han" );

        std::vector< int > vi;
        isOK = settings.GetSetting("e", vi );
        CPPUNIT_ASSERT( isOK );
        CPPUNIT_ASSERT( vi.size() == 2 );
        CPPUNIT_ASSERT( vi[0] == 1 );
        CPPUNIT_ASSERT( vi[1] == 2 );

        MCSettings subSettings;
        isOK = settings.GetSetting( "f", subSettings ); 
        CPPUNIT_ASSERT( isOK );   

    }
    
}